<?php
$script = "jQuery('#cb_createTasks').click(function(){
 	$('#oldTask').hide();
	$('#newTask').show();
});
jQuery('#cb_addToTasks').click(function(){
	$('#newTask').hide();
 	$('#oldTask').show();
});	
jQuery('#cb_allowTasks').click(function(){
	$('#oldTask').hide();
 	$('#newTask').hide();	
});
";

Yii::app()->clientScript->registerScript("cb",$script,CClientScript::POS_READY);

//总是允许
$awayAllow = AdmGroup::model()->getAllowedAccess();
?>

<div class="srbacForm">
  <?php echo CHtml::form() ?>
  <div class="action">
    <?php echo "<b>".$controller."</b>" ?>
  </div>
      
  <?php if (count($actions)>0) { ?>
	<div>
		<table width="100%">
			<tr><td width="55%" style="overflow:hidden">
						<?php echo Yii::t('adm','操作')?>: 
						<?php echo CHtml::checkBox('action',false,array('class'=>'selectAll'))?> 全选
				</td>
			<td width="20%"><?php echo Yii::t('adm','操作名')?></td>
			<td width="25%"><?php echo Yii::t('adm','权限集')?></td></tr>
			<?php foreach($actions as $value){?>
				<tr>
				<td><?php echo CHtml::checkBox('action['.$value.']',false,array('class'=>'iditem'))?> <?php echo $value?></td>
				<td><input type="input" size="13" name="actionName[<?php echo $value?>]" value="<?php echo AdmGroup::model()->getActionName($value)?>"/></td>
				<td>
					<?php 
					$tasksName = AdmGroup::model()->getTasksName($value);
					if(!empty($tasksName)){
						echo $tasksName['zag_title'];
						echo CHtml::link(
								CHtml::image('/images/delete.png',"删除权限"),
								'javascript:',
								array(
									'class'=>'submit_delete',
									'action'=>$value,
									'controller'=>$controller,
									'tasks'=>$tasksName['name'],
								)
							);
					}else{
						if (in_array($value, $awayAllow)) {
							echo Yii::t('adm','alwaysAllowed');
							echo CHtml::link(
									CHtml::image('/images/delete.png',"删除权限"),
									'javascript:',
									array(
											'class'=>'submit_delete',
											'action'=>$value,
											'controller'=>$controller,
											'tasks'=>'awayallow',
									)
							);
						}else{
							echo '';
						}
					}
                	?>
				</td>
				</tr>
			<?php }?>
		</table>
	</div>
  <?php } ?>



  <div class="simple">
    <hr>
    <?php echo Yii::t('adm',"distribute authority").":" ?><br>

      <?php echo CHtml::radioButton("createTasks", true, array("id"=>"cb_createTasks",'class'=>'ml_40','value'=>'1')); ?>
      <?php echo Yii::t('adm','addNewPrivilage') ?>
      <?php echo CHtml::radioButton("createTasks", false, array("id"=>"cb_addToTasks",'class'=>'mr_10','value'=>'2'));?>
      <?php echo Yii::t('adm','addToPrivilage') ?>
      <?php echo CHtml::radioButton("createTasks", false, array("id"=>"cb_allowTasks",'class'=>'mr_10','value'=>'3')); ?>
      <?php echo Yii::t('adm','addallow'); ?>
  </div>
  <div id="newTask">
	  <div class="simple ml_40">
	  		<?php echo Yii::t('adm','权限名称'); ?>:&nbsp;&nbsp;
	      <?php echo CHtml::textField("tasks[user]",'',array('size'=>'30')); ?>
	  </div>
	  <div class="simple ml_40">
	  		<?php echo Yii::t('adm','权限标识'); ?>:&nbsp;&nbsp;
		  <?php echo CHtml::textField("tasks[admin]",AdmGroup::model()->createTaskName($controller),array('size'=>'30',"readonly"=>false)); ?>
	  </div>
  </div>
  <div id="oldTask" class="d_n ml_40">
  		<?php echo Yii::t('adm','选择权限'); ?>:&nbsp;&nbsp;
  		<?php echo CHtml::dropDownList('tasks[old][]','',AdmGroup::model()->getPrivilege(),array('class'=>'mr20','size'=>"8",'multiple'=>'true')); ?>
  		<span class="c_999"><?php echo Yii::t('adm','Hold the ALT key to choose more'); ?></span>
  </div>
  <div class="simple">
    <?php echo CHtml::hiddenField("controller", $controller)?>
  </div>
  <div class="action">
    <?php echo CHtml::button(Yii::t('adm','Save'), array('id'=>'submit_button'))?>
  </div>
  <?php echo CHtml::endForm()?>
</div>

